package com.definity.toolkit.storage;

import java.io.File;
import java.io.InputStream;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.definity.toolkit.domain.Domain;

@Entity
@Table
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
public class StorageData extends Domain<Long> {

	private String name;
	private String group;
	private String extension;
	private String contentType;
	private Long lastModified;
	private Long size;
	private InputStream inputStream;
	
	public StorageData() {

	}
	
	public StorageData(File file) {
		String fileName = file.getName();
		name = fileName.substring(0, fileName.lastIndexOf("."));
		extension = fileName.substring(fileName.lastIndexOf(".") + 1);
		lastModified = file.lastModified();
	}

	@Id
	@GeneratedValue(strategy=GenerationType.TABLE)
	@Override
	public Long getId() {
		return super.getId();
	}

	@Override
	public void setId(Long id) {
		super.setId(id);
	}

	@Column(nullable=true, length=300)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(nullable=true, length=10)
	public String getExtension() {
		return extension;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}

	@Column(nullable=true, length=50)
	public String getContentType() {
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}
	
	@Column(name="fileGroup", nullable=true, length=100)
	public String getGroup() {
		return group;
	}
	
	public void setGroup(String group) {
		this.group = group;
	}

	@Column(nullable=true)
	public Long getLastModified() {
		return lastModified;
	}

	public void setLastModified(Long lastModified) {
		this.lastModified = lastModified;
	}

	@Column(nullable=true)
	public Long getSize() {
		return size;
	}
	
	public void setSize(Long size) {
		this.size = size;
	}
	
	@Transient
	public InputStream getInputStream() {
		return inputStream;
	}
	
	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}
	
}
